/* GUI CONVERTED from reoptr1d.p (converter v1.75) Sat Aug 12 23:07:32 2000 */
/* reoptr1d.p - LABOR OPERATION TRANSACTION SUBROUTINE                  */
/* Copyright 1986-2002 QAD Inc., Carpinteria, CA, USA.                  */
/* All rights reserved worldwide.  This is an unpublished work.         */
/*F0PN*/ /*V8:ConvertMode=Maintenance                                   */
/*K1Q4*/ /*V8:RunMode=Character,Windows                                 */
/* REVISION: 7.3      LAST MODIFIED: 11/04/92   BY: emb *G689*          */
/* REVISION: 7.3      LAST MODIFIED: 02/26/93   BY: emb *G760*          */
/* REVISION: 7.5      LAST MODIFIED: 01/05/95   BY: pma *J040*          */
/* REVISION: 7.3      LAST MODIFIED: 02/15/96   BY: jym *G1N4*          */
/* REVISION: 8.5    LAST MODIFIED: 01/02/97 BY: *G2JV* Julie Milligan   */


/* REVISION: 8.6E     LAST MODIFIED: 02/23/98   BY: *L007* A. Rahane */
/* REVISION: 8.6E     LAST MODIFIED: 05/20/98   BY: *K1Q4* Alfred Tan   */
/* REVISION: 8.6E     LAST MODIFIED: 10/04/98   BY: *J314* Alfred Tan   */
/* REVISION: 9.1      LAST MODIFIED: 03/24/00 BY: *N08T* Annasaheb Rahane */
/* REVISION: 9.1      LAST MODIFIED: 08/12/00 BY: *N0KP* myb              */
         {mfdeclre.i}
{gplabel.i} /* EXTERNAL LABEL INCLUDE */

/* ********** Begin Translatable Strings Definitions ********* */

&SCOPED-DEFINE reoptr1d_p_1 "Routing"
/* MaxLen: Comment: */

&SCOPED-DEFINE reoptr1d_p_2 "Reason"
/* MaxLen: Comment: */

&SCOPED-DEFINE reoptr1d_p_3 "Status"
/* MaxLen: Comment: */

&SCOPED-DEFINE reoptr1d_p_4 "Start Time"
/* MaxLen: Comment: */

&SCOPED-DEFINE reoptr1d_p_5 "Elapsed or Stop Time"
/* MaxLen: Comment: */

&SCOPED-DEFINE reoptr1d_p_6 "Completed"
/* MaxLen: Comment: */

&SCOPED-DEFINE reoptr1d_p_7 "Conv"
/* MaxLen: Comment: */

&SCOPED-DEFINE reoptr1d_p_8 "Chg Attributes"
/* MaxLen: Comment: */

&SCOPED-DEFINE reoptr1d_p_9 "Down Time"
/* MaxLen: Comment: */

&SCOPED-DEFINE reoptr1d_p_10 "BOM"
/* MaxLen: Comment: */

&SCOPED-DEFINE reoptr1d_p_11 "Input Total"
/* MaxLen: Comment: */

&SCOPED-DEFINE reoptr1d_p_12 "Modify Backflush"
/* MaxLen: Comment: */

/* ********** End Translatable Strings Definitions ********* */

         define shared variable site like rps_site no-undo.
         define shared variable prline like rps_line no-undo.
         define shared variable bom_code as character format "x(18)"
            label {&reoptr1d_p_10}.
         define shared variable routing as character format "x(18)"
            label {&reoptr1d_p_1}.
         define shared variable schedule_id like wo_lot.
         define shared variable part like op_part no-undo.

         define variable wocomp like mfc_logical label {&reoptr1d_p_6} initial no.
         define variable wrstatus as character format "X(8)" label {&reoptr1d_p_3}.
         define variable start_setup as character label {&reoptr1d_p_4}
            format "99:99:XX".
         define variable start_run like start_setup.
         define variable stop_setup like start_setup
            label {&reoptr1d_p_5}.
         define variable stop_run like stop_setup.
         define variable i as integer.
         define variable j as integer.
         define variable rsn_desc1 like rsn_desc.
         define variable rsn_desc2 like rsn_desc.
         define variable rsn_desc3 like rsn_desc.
         define variable input_total as decimal format "->>9.9<<"
            label {&reoptr1d_p_11}.
         define variable downtime like input_total extent 5
            label {&reoptr1d_p_9}.
         define variable down_rsn like rsn_code extent 5 label {&reoptr1d_p_2}.
         define variable down_desc like rsn_desc extent 5.
         define variable earn like op_earn.

         define variable mod_issrc like mfc_logical
            label {&reoptr1d_p_12}.

         define shared frame b.

         define variable conv like um_conv label {&reoptr1d_p_7}.
         define variable um like pt_um.
         define variable tot_units like op_qty_comp.
         define variable disp_units as character format "x(15)".

         define variable op like ps_op no-undo.
         define variable msg-type as integer.

/*J040*/ define shared variable chg_attr like mfc_logical
/*J040*/    label {&reoptr1d_p_8} no-undo.
/*G2JV*/ define variable ok like mfc_logical no-undo.
/*G2JV*/ define variable prompt-routing like mfc_logical no-undo.

/*G760*/ {reopf10b.i} /* Frame b definition */

         find pt_mstr no-lock where pt_part = part no-error.

/*G2JV*/       mainloop:
               do on error undo, retry with frame b:
/*GUI*/ if global-beam-me-up then undo, leave.

                  update routing bom_code
                  with frame b editing:
                     if frame-field = "routing" then do:

                        /* FIND NEXT/PREVIOUS RECORD */
                        {mfnp05.i ptr_det ptr_part
                        "ptr_part = part and ptr_site = site"
                         ptr_routing "input routing"}

                        if recno <> ? then do:
                           display ptr_routing @ routing.
                           recno = ?.
                        end.
                     end.
                     else
                     if frame-field = "bom_code" then do:

                        /* FIND NEXT/PREVIOUS RECORD */
                        {mfnp05.i ptr_det ptr_part
                        "ptr_part = part
                         and ptr_site = site
                         and ptr_routing = input routing"
                         ptr_bom_code "input bom_code"}

                        if recno <> ? then do:
                           display ptr_bom_code @ bom_code.
                           recno = ?.
                        end.
                     end.
                     else do:
                        readkey.
                        apply lastkey.
                     end.
                  end.

/*G2JV*/ /* BEGIN ADD SECTION */
                  {gprun.i ""wortbmv.p"" "(input part, input site,
                  input routing,
                  input bom_code, input 3, output ok, output prompt-routing)"}
/*GUI*/ if global-beam-me-up then undo, leave.

                  if not ok then do:
                    if prompt-routing then
                      next-prompt routing.
                    else next-prompt bom_code.
                    undo,retry.
                  end.
                  if routing = "" and
                    not can-find (first ro_det where ro_routing = part)
                  then do:
                    next-prompt routing.
                    /* ROUTING DOES NOT EXISTS */
                    {mfmsg.i 126 3}
                    undo, retry.
                  end.

                end.
/*GUI*/ if global-beam-me-up then undo, leave.
 /* mainloop */
/*G2JV*/ /* END ADD SECTION */

/*G2JV* * * * BEIGN DELETE SECTION *
.                  check-routing: do:
.                     find ptp_det no-lock where ptp_part = part
.                     and ptp_site = site no-error.
.                     if available ptp_det then do:
.                        if routing = ptp_routing
.                        and bom_code = ptp_bom_code
.                        then leave check-routing.
.                     end.
.                     else do:
.                        if routing = pt_routing
.                        and bom_code = pt_bom_code
.                        then leave check-routing.
.                     end.
.
.                     find first ptr_det no-lock where ptr_part = part
.                     and ptr_site = site and ptr_routing = routing no-error.
.
.                     if not available ptr_det then do:
.                        find first ptr_det no-lock where ptr_part = part
.                        and ptr_site = "" and ptr_routing = routing no-error.
.                     end.
.
./*G1N4*              if not available ptr_det then do: */
./*G1N4*/             if not available ptr_det and
./*G1N4*/               routing <> "" and routing <> part
.                       then do:
.
.                        if not (available pt_mstr
.                        and ((available ptp_det
.                        and routing = ptp_routing)
.                        or (not available ptp_det
.                        and routing = pt_routing)))
.                        then do:
.                           msg-type = 3.
.                           {mfmsg.i 150 msg-type}
.                           next-prompt routing.
.                           undo, retry.
.                        end.
.                     end.
.
.                     if (available ptr_det
.                     and bom_code <> ""
.                     and bom_code <> ptr_bom_code and ptr_bom_code <> "")
.
.                     or (not available ptr_det and available ptp_det
.                     and routing = ptp_routing
.                     and bom_code <> ptp_bom_code)
.
.                     or (not available ptr_det and not available ptp_det
.                     and routing = pt_routing
.                     and bom_code <> pt_bom_code)
.                     then do:
.                        msg-type = 3.
.                        {mfmsg.i 152 msg-type}
.                        next-prompt routing.
.                        undo, retry.
.                     end.
.                  end.
.               end.
.
.*G2JV* * * END DELETE SECTION */
               if schedule_id <> "" then do:
                  find wo_mstr no-lock where wo_lot = schedule_id no-error.
                  schedule_id = "".
                  if available wo_mstr
                  and (wo_bom_code = bom_code
                  or (wo_bom_code = wo_part and bom_code = "")
                  or (wo_bom_code = "" and bom_code = wo_part))
                  and (wo_routing = routing
                  or (wo_routing = wo_part and routing = "")
                  or (wo_routing = "" and routing = wo_part))
                  then schedule_id = wo_lot.
               end.
